<?php 
namespace frontend\controllers;
use Yii;
use yii\base\InvalidParamException;
use yii\web\BadRequestHttpException;
use yii\web\UploadedFile;
use yii\web\Controller;
use frontend\models\ComponyMsg;
use frontend\models\UploadForm;
use frontend\models\Position;
use frontend\models\Recruit;
use frontend\models\Apply;
use frontend\models\Resume;
class Compony2Controller extends controller
{
	public $layout='com';

    public function init()
    {
        parent::init();
        session_start();
    }
	public function actionShow()
	{

        //这边需要根据session获取id
        	$id = $_SESSION['user']['user_id'];
			$model=new Recruit();
			$arr=ComponyMsg::find()->where("user_id=$id")->one();
			$type=Position::find()->all();
			if(Yii::$app->request->isGet)
			{
				if ($arr['status']==1) {
					
			 		return $this->render('insert',['type'=>$type]);
				}else if($arr['status']==2){
					echo '<script>alert("审核中,不能访问");location.href="?r=compony2/data"</script>';
				}else{
					echo '<script>alert("审核未通过!不能访问");location.href="?r=compony2/data"</script>';
				}

		 	return $this->render('insert',['type'=>$type]);
		}else{
				$data = Yii::$app->request->post();
				$model->position_type_id=$data['position_type_id'];
				$model->position_name=$data['position_name'];
				$model->recruit_money=$data['recruit_money'];
				$model->recruit_time=$data['recruit_time'];
				$model->recruit_people=$data['recruit_people'];
				$model->work_area=$data['work_area'];
				$model->recruit_content=$data['recruit_content'];
				$model->recruit_area=$data['recruit_area'];
				$model->user_id=$id;
				$model->time=time();
				$model->insert();
				echo "<script>alert('添加成功');location.href='?r=compony2/data';</script>";
		}

		
	}
	public function actionData()
	{
        //这边需要根据session获取id
        $id = $_SESSION['user']['user_id'];
        $arr=ComponyMsg::find()->where("user_id=$id")->one();
        return $this->render('show',['arr'=>$arr]);
	}
	public function actionPaudit(){

        //这边需要根据session获取id
        $id = $_SESSION['user']['user_id'];
        $arr=Apply::find()->where("compony_id=$id and status=2")->all();
  		if (!empty($arr)) {

		  foreach ($arr as $key => $val) {
		  	  $user_id[$key]=$arr[$key]->user_id;
			  $recruit_id[$key]=$arr[$key]->recruit_id;
			  $status[$key]=$arr[$key]->status;
		  }
		  foreach ($user_id as $key => $val) {
		  	  foreach ($recruit_id as $k => $v) {
		  	   $resume=Resume::find()->where("user_id=$val")->one();
		  	   $res=Recruit::find()->where("recruit_id=$v")->one();
		  	   $data['resume'][$key]['resume_id']=$resume->resume_id;
		  	   $data['resume'][$key]['resume_name']=$resume->resume_name;
		  	   $data['resume'][$key]['resume_sex']=$resume->resume_sex;
		  	   $data['resume'][$key]['resume_degree']=$resume->resume_degree;
		  	   $data['resume'][$key]['resume_experience']=$resume->resume_experience;
		  	   $data['resume'][$key]['resume_tel']=$resume->resume_tel;
		  	   $data['resume'][$key]['resume_email']=$resume->resume_email;
		  	   $data['resume'][$key]['resume_img']=$resume->resume_img;
		  	   $data['resume'][$key]['company_name']=$resume->company_name;
		  	   $data['resume'][$key]['position_name']=$resume->position_name;
		  	   $data['resume'][$key]['begin_year']=$resume->begin_year;
		  	   $data['resume'][$key]['begin_month']=$resume->begin_month;
		  	   $data['resume'][$key]['end_year']=$resume->end_year;
		  	   $data['resume'][$key]['my_content']=$resume->my_content;
		  	   $data['resume'][$key]['time']=$resume->time;
		  	   $data['resume'][$key]['user_id']=$resume->user_id;
		  	   $data['resume'][$key]['position_name']=$res->position_name;
		  	   $data['resume'][$key]['recruit_id']=$res->recruit_id;
			  }
		     } 
	     	   	$count=count($data['resume']);
		  		return $this->render('paudit',['data'=>$data,'count'=>$count]);
		  	}else{
			    echo "<script>alert('没有待审核的简历');location.href='?r=compony2/data'</script>";
		}
	}
	public function actionNaudit()
	{
        //这边需要根据session获取id
        $id = $_SESSION['user']['user_id'];
        $arr=Apply::find()->where("compony_id=$id and status!=2")->all();
  		if (!empty($arr)) {

		  foreach ($arr as $key => $val) {
		  	  $user_id[$key]=$arr[$key]->user_id;
			  $recruit_id[$key]=$arr[$key]->recruit_id;
			  $status[$key]=$arr[$key]->status;
		  }
		  foreach ($user_id as $key => $val) {
		  	  foreach ($recruit_id as $k => $v) {
		  	  	foreach ($status as $ke => $va) {
		  	   $resume=Resume::find()->where("user_id=$val")->one();
		  	   $res=Recruit::find()->where("recruit_id=$v")->one();
		  	   $data['resume'][$key]['resume_id']=$resume->resume_id;
		  	   $data['resume'][$key]['resume_name']=$resume->resume_name;
		  	   $data['resume'][$key]['resume_sex']=$resume->resume_sex;
		  	   $data['resume'][$key]['resume_degree']=$resume->resume_degree;
		  	   $data['resume'][$key]['resume_experience']=$resume->resume_experience;
		  	   $data['resume'][$key]['resume_tel']=$resume->resume_tel;
		  	   $data['resume'][$key]['resume_email']=$resume->resume_email;
		  	   $data['resume'][$key]['resume_img']=$resume->resume_img;
		  	   $data['resume'][$key]['company_name']=$resume->company_name;
		  	   $data['resume'][$key]['position_name']=$resume->position_name;
		  	   $data['resume'][$key]['begin_year']=$resume->begin_year;
		  	   $data['resume'][$key]['begin_month']=$resume->begin_month;
		  	   $data['resume'][$key]['end_year']=$resume->end_year;
		  	   $data['resume'][$key]['my_content']=$resume->my_content;
		  	   $data['resume'][$key]['time']=$resume->time;
		  	   $data['resume'][$key]['user_id']=$resume->user_id;
		  	   $data['resume'][$key]['position_name']=$res->position_name;
		  	   $data['resume'][$key]['recruit_id']=$res->recruit_id;
		  	   $data['resume'][$key]['status']=$status[$key];
		  		}
			  }
		     } 
	     	   	$count=count($data['resume']);
		  		return $this->render('naudit',['data'=>$data,'count'=>$count]);
		  	}else{
			    echo "<script>alert('没有审核结束的简历');location.href='?r=compony2/data'</script>";
		}
	}
	public function actionAjax()
	{
		      $status=Yii::$app->request->get('status');
		      $user_id=Yii::$app->request->get('user_id');
		      $recruit_id=Yii::$app->request->get('recruit_id');
		      $arr=Recruit::findOne($recruit_id);
		      $arr->recruit_people=$arr->recruit_people-1;
		      $arr->save();
		      $db=Yii::$app->db;
		      $command = $db->createCommand("UPDATE e_apply SET status=$status WHERE user_id=$user_id and recruit_id=$recruit_id");
			  $res=$command->execute();
		      if ($res) {
		      	echo 1;
		      }else{
		      	echo 0;
		      }
		     
	}
	public function actionPosition()
	{
			$id = $_SESSION['user']['user_id'];
			$arr=Recruit::find()->where("user_id=$id")->all();
			$count=count($arr);
			return $this->render('position',['arr'=>$arr,'count'=>$count]);
	}
	
}








 ?>